<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:p="http://primefaces.org/ui">


<ui:composition template="/WEB-INF/templates/maintemplate.xhtml">
	<ui:define name="metadata">
		<!-- save cagtThdId in sessionScope, DO NOT USE flash Scope.  -->
		<f:metadata>
			<f:viewParam name="#{constants.nameToValueMap.CATEGORY__THREAD_ID}" value="${sessionScope.ctgtThdId}"></f:viewParam>
		</f:metadata>
	</ui:define>
	<ui:define name="navigation">
		<h:panelGroup>
			<f:event type="preRenderComponent" listener="#{threadBackingBean.calculateNavMap()}" />
			<ui:include src="/navigation.xhtml"></ui:include>
		</h:panelGroup>
	</ui:define>

	<ui:define name="content">
		<div class="listThreadContainer">
			<h:form>
				<p:dataTable var="thread" value="#{threadBackingBean.lazyThreadDataModel}" paginator="true" rows="20" lazy="true"
					paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink}  {PageLinks}  {CurrentPageReport} {NextPageLink} {LastPageLink}"
					rowsPerPageTemplate="5,10,15" tableStyleClass="noBorderTable" paginatorPosition="bottom">
					<p:column headerText="#{msgs.threadSubjectLabel}" styleClass="mainColumn">
						<h:graphicImage name="TopTopic.gif" library="images" rendered="#{thread.topped}" />
						<h:graphicImage name="TopicNew.gif" library="images" rendered="#{!thread.topped}" />
						<h:link value="#{thread.subject}" outcome="viewthread" styleClass="longstyle">
							<f:param name="id" value="#{thread.id}"></f:param>
						</h:link>
					</p:column>

					<p:column headerText="#{msgs.threadReplyHitLabel}">
						<h:outputText value='#{thread.numberOfReplies}/#{thread.numberOfView}' escape="false"></h:outputText>
					</p:column>
					<p:column headerText="#{msgs.threadAuthorLabel}">
						<h:outputText value='#{thread.owner.userId}' escape="false"></h:outputText>
					</p:column>

					<p:column headerText="#{msgs.threadLastUpdateLabel}">
						<h:panelGroup rendered="#{thread.lastReply!=null}">
							<h:outputText value="#{thread.lastReply.owner.userId}" styleClass="block" />
							<h:outputFormat value="#{thread.lastReply.createTime}">
								<f:convertDateTime dateStyle="short" timeStyle="short" type="both" />
							</h:outputFormat>
						</h:panelGroup>
						<h:panelGroup rendered="#{thread.lastReply==null}">
							<h:outputText value="--/--" />
						</h:panelGroup>
					</p:column>
					<p:column headerText="#{msgs.threadAuthorLabel}" rendered="#{threadBackingBean.ownerForCurrCategory || login.userInSysadmin}">
						<p:commandButton value="#{msgs.deleteButton}" actionListener="#{threadBackingBean.deleteThread(thread)}" update="@form" process="@form">
						</p:commandButton>

						<p:commandButton value="#{msgs.Top_Button}" actionListener="#{threadBackingBean.topThread(thread,true)}" process="@form" update="@form"
							rendered="#{!thread.topped}">
						</p:commandButton>
						<p:commandButton value="#{msgs.Untop_Button}" actionListener="#{threadBackingBean.topThread(thread,false)}" process="@form" update="@form"
							rendered="#{thread.topped}">
						</p:commandButton>

						<p:commandButton value="#{msgs.DashBoard}" actionListener="#{threadBackingBean.dashBoardThread(thread)}" process="@form" update="@form"
							rendered="#{!thread.onDashBoard}">
						</p:commandButton>
						<p:commandButton value="#{msgs.OutDashBoard}" actionListener="#{threadBackingBean.unDashBoardThread(thread)}" process="@form" update="@form"
							rendered="#{thread.onDashBoard}">
						</p:commandButton>
					</p:column>

				</p:dataTable>
				<div style="display: inline; float: left; margin-top: 10px;">
					<p:button value="#{msgs.postNewThread}" outcome="createthread">
					</p:button>
				</div>

			</h:form>
		</div>
	</ui:define>

</ui:composition>

</html>